package com.voda.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.voda.dao.api.IRoleDao;
import com.voda.dao.impl.common.AbstractDaoImpl;
import com.voda.entity.Role;

/**
 * The Class RoleDaoImpl.
 */
@Repository
public class RoleDaoImpl extends AbstractDaoImpl<Role> implements IRoleDao {

	private static final String PROP_NAME = "name";

	/**
	 * Instantiates a new role dao impl.
	 */
	public RoleDaoImpl() {
		super(Role.class);
	}

	@Override
	public Role getRoleByName(String roleName) {
		
		Criteria criteria = getSession().createCriteria(Role.class);
		criteria.add(Restrictions.eq(PROP_NAME, roleName));
		
		return (Role) criteria.uniqueResult();
	}

}
